
package com.catsic.zcjc.specifiction;

import javax.persistence.criteria.Path;

import org.apache.commons.collections.CollectionUtils;

import com.catsic.base.specification.BaseSpec;
import com.catsic.base.specification.QueryWraper;
import com.catsic.core.entity.Organ;
import com.catsic.zcjc.condition.StationCondition;
import com.catsic.zcjc.entity.District;
import com.catsic.zcjc.entity.Station;

public class StationSpec extends BaseSpec<Station> {

	public StationSpec(StationCondition condition){
		super(condition);
	}
	

	@Override
	protected void addCondition(QueryWraper<Station> queryWraper) {
		StationCondition condition = (StationCondition) getCondition();
		addLikeCondition(queryWraper, "name");
		this.addEqualCondition(queryWraper, "type");
		
		/**
		 * 多表联查,多对一,机构
		 */
		Path<Organ> organ = queryWraper.getRoot().get("organ");
		addEqualCondition(queryWraper, organ.get("id"),condition.getOrganId());
		
		
		if(CollectionUtils.isNotEmpty(condition.getAreaIdList())){
			Path<District> area = queryWraper.getRoot().get("cityCode");
			this.addInCondition(queryWraper, area.get("id"), condition.getAreaIdList());
		}
		
		/**
		 * 自定义排序
		 */
		queryWraper.addOrder(queryWraper.getCb().asc(queryWraper.getRoot().get("code")));
	    
		
	}
}
